Crate cubob

source ·
Expand description

Some primitives to simplify implementation of structured data output in display mode. Usage example:

use core::fmt::{Display, Formatter, Result as FmtResult};
use cubob::display_struct;

struct Point {
    x: i32,
    y: i32,
}

struct Line {
    a: Point,
    b: Point,
}

impl Display for Point {
    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
        display_struct(
            f,
            &[
                (&"x", &self.x),
                (&"y", &self.y),
            ],
        )
    }
}

impl Display for Line {
    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
        display_struct(
            f,
            &[
                (&"a", &self.a),
                (&"b", &self.b),
            ],
        )
    }
}

let line = Line{ a: Point{ x: 0, y: 0}, b: Point{ x: 1, y: 1} };
println!("One-line: {}", line);
println!("Prettified: {:#}", line);

Structs

Fieldfield
Lets to output key-value pair regarding the propagated value of output alternativeness.
InstantListlist and instant
Struct used to simplify displaying of any iterable lists.
InstantStructstruct and instant
Struct used to simplify displaying of any iterable maps.
Lets to output some listed data regarding the propagated value of output alternativeness.
Passage(list or struct) and instant
Type implementing Kind and used to mark types which are treated as Iterator and not IntoIterator.
Source(list or struct) and instant
Type implementing Kind and used to mark types which are treated as IntoIterator and not Iterator.
Lets to output some structure regarding the propagated value of output alternativeness.

Enums

Alternate mode to use while outputting.

Traits

Trait used to generalize over tuples of displayable types and references onto such tuples. Trait is not sealed and can be implementd for any other needed type.
EmbedListlist and embed
Trait letting to define embedding of implementing type list output into other type list output.
EmbedStructstruct and embed
Trait letting to define embedding of implementing type struct output into other type struct output.
Iterable(list or struct) and instant
Trait used to generalize over IntoIterator+Copy and Iterator+Clone types. Actual used source is defined via type parameter which should implement Kind trait. There can be some problems when type implements Iterator and Copy simultaneously: since every Iterator automatically implements IntoIterator, and Copy implementation requires Clone implementation too, such type will suit both alternatives and will cause conflict until explicit Kind specified. Trait is not sealed, so any user can define own Iterable implementation.
Kind(list or struct) and instant
Special trait, generalizing all the types used to distinguish different types of iterable data sources. Those types can be either type, implementing IntoIterator and Copy (so usual reference on IntoIterator suits) or type, implementing Iterator and Clone. There can be some problems when type implements Iterator and Copy simultaneously: since every Iterator automatically implements IntoIterator, and Copy implementation requires Clone implementation too, such type will suit both alternatives and will cause conflict until explicit Kind specified. Trait is not sealed, so any user can define own kind and use it along with own Iterable implementation for that kind.

Functions

Performs the whole list output routine from creation of ListShow examplar to finishing. Works with slice, always inherits alternate mode.
Routine to simplify Display implementation for type which already implements EmbedList.
Performs the whole list output routine from creation of ListShow examplar to finishing. Works with iterator, always inherits alternate mode.
Performs the whole struct output routine from creation of StructShow examplar to finishing (for example see the crate-level documentation). Works with slice, always inherits alternate mode.
Routine to simplify Display implementation for type which already implements EmbedStruct.
Performs the whole struct output routine from creation of StructShow examplar to finishing. Works with iterator, always inherits alternate mode.